module.exports=class student_mod extends require('./model'){

  /**
   * 分页获取我的通知和数量
   * @param u_classes
   * @param pageNum
   * @param currPage
   * @returns {Promise<unknown>}
   */
  static getNoticeMod(u_classes,pageNum,currPage){
  pageNum=Number(pageNum)
  currPage=Number(currPage)
  currPage=Number(pageNum*currPage)
  return new Promise((resolve, reject) => {
    let sql="select * from notice where class like '%"+u_classes+"%' order by createtime desc limit ?,?"
    this.query(sql,this.formatParams(currPage,pageNum)).then(result=>{
      resolve(result)
    }).catch(err=>{
      reject(err)
    })
  })
}

static getNoticeTotal(u_classes){
    return new Promise((resolve, reject) => {
      let sql="select count(1) as count from notice where class like '%"+u_classes+"%'"
      this.query(sql).then(result=>{
        resolve(result)
      }).catch(err=>{
        reject(err)
      })
    })
}

  /**
   * 获取我的已读通知
   * @param u_id
   */

static getNoticeReadMod(u_id){
    return new Promise((resolve, reject) => {
      let sql="select * from `read` where u_id=?"
      this.query(sql,this.formatParams(u_id)).then(result=>{
        resolve(result)
      }).catch(err=>{
        reject(err)
      })
    })
}

  /**
   * 未读转已读
   * @param u_id
   * @param n_id
   */
  static goReadilyMod(u_id,n_id){
    u_id=Number(u_id)
    n_id=Number(n_id)
    return new Promise((resolve, reject) => {
      let sql="insert into `read` (u_id,n_id) values (?,?)"
      this.query(sql,this.formatParams(u_id,n_id)).then(result=>{
        resolve('未读转已读成功')
      }).catch(err=>{
        console.log('未读转已读失败')
        reject(err)
      })
    })
}

  /**
   * 健康报表添加
   * @param u_id
   * @param temperature
   * @param name
   * @param classes
   * @param living
   * @param ferver
   * @param leaveout
   * @param nucleic
   * @returns {Promise<unknown>}
   */
  static setHealtyMod(u_id,name,classes,living,healthy,leaveout,nucleic,phone){
    return new Promise((resolve, reject) => {
      let sql="insert into `health` (u_id,name,classes,living,healthy,leaveout,nucleic,phone) values(?,?,?,?,?,?,?,?)"
      this.query(sql,this.formatParams(u_id,name,classes,living,healthy,leaveout,nucleic,phone)).then(result=>{
        console.log(sql)
        resolve(result)
      }).catch(err=>{
        reject(err)
      })
    })
  }

  /**
   * 分页获取当天报表与数量
   * @param newDate
   * @param lastDate
   * @param currPage
   * @param pageNum
   * @returns {Promise<unknown>}
   */
  static getHealtyNowadayMod(newDate,lastDate,currPage,pageNum){
     currPage=Number(currPage)
      pageNum=Number(pageNum)
    currPage=Number(currPage*pageNum)
    return new Promise((resolve, reject) => {
      let sql="select * from health where createtime between ? and ? LIMIT ?,?"
      this.query(sql,this.formatParams(newDate,lastDate,currPage,pageNum)).then(result=>{
        resolve(result)
      }).catch(err=>{
        reject(err)
      })
    })
  }

  static getHealtyNowadayTotal(newDate,lastDate){
    return new Promise((resolve, reject) => {
      let sql="select count(1) as count from health where createtime between ? and ?"
      this.query(sql,this.formatParams(newDate,lastDate)).then(result=>{
        resolve(result)
      }).catch(err=>{
        reject(err)
      })
    })
  }

  /**
   * 获取当天某用户的报表
   * @param u_id
   * @param newDate
   * @param lastDate
   * @returns {Promise<unknown>}
   */
  static getHealtyNowadaByidMod(u_id,newDate,lastDate){
    return new Promise((resolve, reject) => {
      let sql="select * from health where (createtime between ? and ?) and u_id=?"
      this.query(sql,this.formatParams(newDate,lastDate,u_id)).then(result=>{
        resolve(result)
      }).catch(err=>{
        reject('查询失败')
      })
    })
  }

  static getuserinfoMod(u_id){
    return new Promise((resolve, reject) => {
      let sql="select * from user where id=?"
      this.query(sql,this.formatParams(u_id)).then(result=>{
        resolve(result)
      }).catch(err=>{
        reject(err)
      })
    })
  }

  /**
   * 请假申请
   * @param u_id
   * @param classes
   * @param reason
   * @param leavetype
   * @param starttime
   * @param endtime
   * @returns {Promise<unknown>}
   */
  static setleaveMod(u_id,classes,reason,leavetype,starttime,endtime){
    return new Promise((resolve, reject) => {
      let sql="insert into `leave` (u_id,classes,reason,leavetype,starttime,endtime) values(?,?,?,?,?,?)"
      this.query(sql,this.formatParams(u_id,classes,reason,leavetype,starttime,endtime)).then(result=>{
        resolve('请假申请成功')
      }).catch(err=>{
        reject('请假申请失败')
      })
    })
  }

  static getleavebyidMod(u_id){
    return new Promise((resolve, reject) => {
      let sql="select * from `leave` where u_id="+u_id+" order by createtime DESC"
      this.query(sql).then(result=>{
        resolve(result)
      }).catch(err=>{
        reject(err)
      })
    })
  }
}
